package com.health.tools;

import android.text.TextUtils;
import android.util.Log;

import com.health.db.FDbManager;

import com.health.model.FeiXinBingFollowupNew;
import com.health.model.FengShiBingFollowupNew;
import com.health.model.LeiFengShiFollowupNew;
import com.health.model.LvYueFuWuBean;
import com.health.model.ManZuFeiFollowupNew;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.ARCHIVE_CUSTOMERBASEINFO;
import com.health.tablebean.CD_DIABETESFOLLOWUP;
import com.health.tablebean.CD_HYPERTENSIONFOLLOWUP;
import com.health.tablebean.CD_MENTALDISEASE_BASEINFO;
import com.health.tablebean.CD_MENTALDISEASE_FOLLOWUP;
import com.health.tablebean.CD_TUBERCULOSIS_BASEINFO;
import com.health.tablebean.CD_TUBERCULOSIS_FOLLOWUP;
import com.health.tablebean.CHILD_NEWBORN_FOLLOWUP;
import com.health.tablebean.CHILD_ONE2THREE_YEAR_OLD;
import com.health.tablebean.CHILD_THREE2SIX_YEAR_OLD;
import com.health.tablebean.CHILD_WITHIN_ONE_YEAR_OLD;
import com.health.tablebean.GRAVIDA_FIRSTFOLLOWUP;
import com.health.tablebean.GRAVIDA_POSTPARTUM;
import com.health.tablebean.GRAVIDA_POSTPARTUM_42DAY;
import com.health.tablebean.GRAVIDA_TWO2FIVE_FOLLOWUP;
import com.health.tablebean.JTYSCustomerDoctorCont;
import com.health.tablebean.JTYSDoctorEvaluateBean;
import com.health.tablebean.JTYS_SignPictureData;
import com.health.tablebean.OLDER_SELFCAREABILITY;
import com.health.tablebean.OLD_MEDICINE_CN;
import com.health.tablebean.webservice.CoronaryHeartDisease;
import com.health.tablebean.webservice.HdDiseaseManageStroke;
import com.health.viewscontrols.NovaApplication;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * 上传数据工具类
 */
public class JX_UploadData {
    public static final String TYPE_PERSONALINFO = "PersonalInfo";// 个人基本信息
    public static final String TYPE_HYPERTENSION = "Hypertension";// 高血压
    public static final String TYPE_CEREBRALSTROKE = "cerebralStroke";// 脑卒中
    public static final String TYPE_CORONARYHEART = "CoronaryHeart";// 冠心病
    public static final String TYPE_JsjbBaseInfo = "JsjbBaseInfo";//精神病基本信息
    public static final String TYPE_JSJBSF = "Jsjbsfb";//精神病随访
    public static final String TYPE_DIABETES = "Diabetes";// 糖尿病
    /**
     * 肺结核第一次随访
     */
    public static final String TYPE_TUBERCULOSIS_BASE_INFO = "TuberculosisBaseInfo";
    /**
     * 肺结核随访信息
     */
    public static final String TYPE_TUBERCULOSIS_FOLLOW_INFO = "TuberculosisFollowInfo";
    public static final String TYPE_HEALTHCHECK = "HealthCheck";// 健康查体
    private final static FDbManager fdbManage = NovaApplication.fdbmanger;
    public static final String TYPE_OLD_PHYSIQUE = "old";// 老年人中医药健康管理
    public static final String TYPE_OLD_SELF_HELP = "old1";// 老年人自理能力
    public static final String TYPE_QYYH = "qyyh";// 签约用户
    public static final String TYPE_FWMYD = "fwmyd";// 服务满意度用户
    public static final String TYPE_PICTURE = "picture";// 图片
    public static final String TYPE_XSRFS = "xsrfs";//新生儿访视
    public static final String TYPE_ONEMONTH = "oneMonth";//满月龄访视
    public static final String TYPE_THREEMONTH = "threeMonth";//三月龄访视
    public static final String TYPE_SIXMONTH = "sixMonth";//六月龄访视
    public static final String TYPE_EIGHTMONTH = "eightMonth";//八月龄访视
    public static final String TYPE_LVYUEJL="lvyueJL";//履约记录
    public static final String TYPE_FEIXINBING="feiXinBing";//肺心病随访
    public static final String TYPE_LEIFENGSHI="leifengshi";//类风湿随访
    public static final String TYPE_FENGSHIBING="fengshibing";//风湿病随访
    public static final String TYPE_MANZUFEI="manzufei";//慢阻肺随访
    /**
     * 12月龄访视
     */
    public static final String TYPE_12MONTH = "12Month";
    /**
     * 18月龄访视
     */
    public static final String TYPE_18MONTH = "18Month";
    /**
     * 24月龄访视
     */
    public static final String TYPE_24MONTH = "24Month";
    /**
     * 30月龄访视
     */
    public static final String TYPE_30MONTH = "30Month";
    /**
     * 3岁龄访视
     */
    public static final String TYPE_3YEAR = "3Year";
    /**
     * 4岁龄访视
     */
    public static final String TYPE_4YEAR = "4Year";
    /**
     * 5岁龄访视
     */
    public static final String TYPE_5YEAR = "5Year";
    /**
     * 6岁龄访视
     */
    public static final String TYPE_6YEAR = "6Year";
    /**
     * 产前随访第一次
     */
    public static final String TYPE_1TIMES = "1Times";
    /**
     * 产前随访第二次
     */
    public static final String TYPE_2TIMES = "2Times";
    /**
     * 产前随访第三次
     */
    public static final String TYPE_3TIMES = "3Times";
    /**
     * 产前随访第四次
     */
    public static final String TYPE_4TIMES = "4Times";
    /**
     * 产前随访第五次
     */
    public static final String TYPE_5TIMES = "5Times";
    /**
     * 产后访视
     */
    public static final String TYPE_POSTNATAL_VISITS = "postnatal_visits";
    /**
     * 产后四十二天访视
     */
    public static final String TYPE_42DAYS = "42Days";


    @SuppressWarnings("finally")
    public static int[] jx_data(String result, String upType) {
        Log.e("上传返回字符串",result+"***********");
        JSONArray jsons;
        int i1 = 0;
        int i2 = 0;
        try {
            jsons = new JSONArray(result);
            int length = jsons.length();
            if (length > 0) {
                for (int i = 0; i < length; i++) {

                    JSONObject obj = jsons.getJSONObject(i);
                    String state = obj.getString("state");
                    String personalid = obj.getString("personalid");
                    String fieldname=obj.getString("fieldname");
                    String cardid = "";
                    if (obj.has("cardid")) {
                        cardid = obj.getString("cardid");
                    }
                    String cardNum = "";
                    if (obj.has("cardNum")) {
                        cardNum = obj.getString("cardNum");
                    }
                    if(TextUtils.isEmpty(cardid)){
                        cardid=cardNum;
                    }else if(TextUtils.isEmpty(cardNum)){
                        cardNum=cardid;
                    }
                    if (state.equals("000")) {
                        i1++;
                        // 插入成功
                        if (upType.equals(TYPE_PERSONALINFO)) {
                            // 个人基本信息
                            List<ARCHIVE_BASEINFO> findAllByWhere = fdbManage.findAllByWhere(ARCHIVE_BASEINFO.class,
                                    "IDCARD ='" + cardid + "'");
                            if (findAllByWhere.size() > 0) {
                                ARCHIVE_BASEINFO archive_BASEINFO = findAllByWhere.get(0);
                                archive_BASEINFO.setIS_UPDATE("N");
                                archive_BASEINFO.setARCHIVEID(personalid);
                                fdbManage.updata(archive_BASEINFO, "IDCARD ='" + cardid + "'");
                            }else{
                                List<ARCHIVE_BASEINFO> findAllByWhere1 = fdbManage.findAllByWhere(ARCHIVE_BASEINFO.class,
                                        "IDCARD ='" + cardid.toLowerCase() + "'");
                                if(findAllByWhere1.size()>0){
                                    ARCHIVE_BASEINFO archive_BASEINFO = findAllByWhere1.get(0);
                                    archive_BASEINFO.setIS_UPDATE("N");
                                    archive_BASEINFO.setARCHIVEID(personalid);
                                    fdbManage.updata(archive_BASEINFO, "IDCARD ='" + cardid.toLowerCase() + "'");
                                }
                            }
                        } else if (upType.equals(TYPE_HYPERTENSION)) {
                            String happentime=obj.getString("happentime");
                            // 高血压
                            List<CD_HYPERTENSIONFOLLOWUP> findAllByWhere = fdbManage
                                    .findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class, "IDCARD ='" + cardid + "' and FOLLOWUPDATE='"+happentime+" 00:00:00' ");
                            if (findAllByWhere.size() > 0) {
                                CD_HYPERTENSIONFOLLOWUP cd_HYPERTENSIONFOLLOWUP = findAllByWhere.get(0);
                                cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "IDCARD ='" + cardid + "' and FOLLOWUPDATE='"+happentime+" 00:00:00' ");
                            }else{
                                List<CD_HYPERTENSIONFOLLOWUP> findAllByWhere1 = fdbManage
                                        .findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class, "IDCARD ='" + cardid.toLowerCase() + "' and FOLLOWUPDATE='"+happentime+" 00:00:00'");
                                if(findAllByWhere1.size()>0){
                                    CD_HYPERTENSIONFOLLOWUP cd_HYPERTENSIONFOLLOWUP = findAllByWhere1.get(0);
                                    cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                    fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "IDCARD ='" + cardid.toLowerCase() + "' and FOLLOWUPDATE='"+happentime+" 00:00:00' " );
                                }
                            }

                                List<CD_HYPERTENSIONFOLLOWUP> findAllByWhere2 = fdbManage
                                        .findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class, "ARCHIVEID ='" + personalid + "'");
                                if(findAllByWhere2.size()>0){
                                    CD_HYPERTENSIONFOLLOWUP cd_HYPERTENSIONFOLLOWUP = findAllByWhere2.get(0);
                                    cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                    fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "ARCHIVEID ='" + personalid + "'");
                                }

                        } else if (upType.equals(TYPE_CEREBRALSTROKE)) {
                            // 脑卒中
                            List<HdDiseaseManageStroke> findAllByWhere = fdbManage
                                    .findAllByWhere(HdDiseaseManageStroke.class, "cardid ='" + cardid + "'");
                            if (findAllByWhere.size() > 0) {
                                HdDiseaseManageStroke cd_HYPERTENSIONFOLLOWUP = findAllByWhere.get(0);
                                cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "cardid ='" + cardid + "'");
                            }else{
                                List<HdDiseaseManageStroke> findAllByWhere1 = fdbManage
                                        .findAllByWhere(HdDiseaseManageStroke.class, "cardid ='" + cardid.toLowerCase() + "'");
                                if(findAllByWhere1.size()>0){
                                    HdDiseaseManageStroke cd_HYPERTENSIONFOLLOWUP = findAllByWhere1.get(0);
                                    cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                    fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "cardid ='" + cardid.toLowerCase() + "'");
                                }
                            }

                                List<HdDiseaseManageStroke> findAllByWhere2 = fdbManage
                                        .findAllByWhere(HdDiseaseManageStroke.class, "ARCHIVEID ='" + personalid + "'");
                                if(findAllByWhere2.size()>0){
                                    HdDiseaseManageStroke cd_HYPERTENSIONFOLLOWUP = findAllByWhere2.get(0);
                                    cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                    fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "ARCHIVEID ='" + personalid + "'");
                                }

                        } else if (upType.equals(TYPE_CORONARYHEART)) {
                            // 冠心病
                            List<CoronaryHeartDisease> findAllByWhere = fdbManage
                                    .findAllByWhere(CoronaryHeartDisease.class, "cardid ='" + cardid + "'");
                            if (findAllByWhere.size() > 0) {
                                CoronaryHeartDisease cd_CHD_FOLLOWUP = findAllByWhere.get(0);
                                cd_CHD_FOLLOWUP.setIS_UPDATE("N");
                                fdbManage.updata(cd_CHD_FOLLOWUP, "cardid ='" + cardid + "'");
                            }else{
                                List<CoronaryHeartDisease> findAllByWhere1 = fdbManage
                                        .findAllByWhere(CoronaryHeartDisease.class, "cardid ='" + cardid.toLowerCase() + "'");
                                if(findAllByWhere1.size()>0){
                                    CoronaryHeartDisease cd_CHD_FOLLOWUP = findAllByWhere1.get(0);
                                    cd_CHD_FOLLOWUP.setIS_UPDATE("N");
                                    fdbManage.updata(cd_CHD_FOLLOWUP, "cardid ='" + cardid.toLowerCase() + "'");
                                }
                                    List<CoronaryHeartDisease> findAllByWhere2 = fdbManage
                                            .findAllByWhere(CoronaryHeartDisease.class, "ARCHIVEID ='" + personalid + "'");
                                    if(findAllByWhere2.size()>0){
                                        CoronaryHeartDisease cd_HYPERTENSIONFOLLOWUP = findAllByWhere2.get(0);
                                        cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                        fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "ARCHIVEID ='" + personalid + "'");
                                    }
                            }
                        } else if (upType.equals(TYPE_JsjbBaseInfo)) {
                            //精神病基本信息
                            List<CD_MENTALDISEASE_BASEINFO> findAllByWhere = fdbManage
                                    .findAllByWhere(CD_MENTALDISEASE_BASEINFO.class, "IDCARD ='" + cardid + "'");
                            if (findAllByWhere.size() > 0) {
                                CD_MENTALDISEASE_BASEINFO cd_HYPERTENSIONFOLLOWUP = findAllByWhere.get(0);
                                cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "IDCARD ='" + cardid + "'");
                            }else{
                                List<CD_MENTALDISEASE_BASEINFO> findAllByWhere1 = fdbManage
                                        .findAllByWhere(CD_MENTALDISEASE_BASEINFO.class, "IDCARD ='" + cardid.toLowerCase() + "'");
                                if(findAllByWhere1.size()>0){
                                    CD_MENTALDISEASE_BASEINFO cd_HYPERTENSIONFOLLOWUP = findAllByWhere1.get(0);
                                    cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                    fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "IDCARD ='" + cardid.toLowerCase() + "'");
                                }
                                    List<CD_MENTALDISEASE_BASEINFO> findAllByWhere2 = fdbManage
                                            .findAllByWhere(CD_MENTALDISEASE_BASEINFO.class, "ARCHIVEID ='" + personalid + "'");
                                    if(findAllByWhere2.size()>0){
                                        CD_MENTALDISEASE_BASEINFO cd_HYPERTENSIONFOLLOWUP = findAllByWhere2.get(0);
                                        cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                        fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "ARCHIVEID ='" + personalid + "'");
                                    }
                            }
                        } else if (upType.equals(TYPE_JSJBSF)) {
                            //精神病随访
                            List<CD_MENTALDISEASE_FOLLOWUP> findAllByWhere = fdbManage
                                    .findAllByWhere(CD_MENTALDISEASE_FOLLOWUP.class, "IDCARD ='" + cardid + "'");
                            if (findAllByWhere.size() > 0) {
                                CD_MENTALDISEASE_FOLLOWUP cd_HYPERTENSIONFOLLOWUP = findAllByWhere.get(0);
                                cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "IDCARD ='" + cardid + "'");
                            }else{
                                List<CD_MENTALDISEASE_FOLLOWUP> findAllByWhere1 = fdbManage
                                        .findAllByWhere(CD_MENTALDISEASE_FOLLOWUP.class, "IDCARD ='" + cardid.toLowerCase() + "'");
                                if(findAllByWhere1.size()>0){
                                    CD_MENTALDISEASE_FOLLOWUP cd_HYPERTENSIONFOLLOWUP = findAllByWhere1.get(0);
                                    cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                    fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "IDCARD ='" + cardid.toLowerCase() + "'");
                                }
                                    List<CD_MENTALDISEASE_FOLLOWUP> findAllByWhere2 = fdbManage
                                            .findAllByWhere(CD_MENTALDISEASE_FOLLOWUP.class, "ARCHIVEID ='" + personalid + "'");
                                    if(findAllByWhere2.size()>0){
                                        CD_MENTALDISEASE_FOLLOWUP cd_HYPERTENSIONFOLLOWUP = findAllByWhere2.get(0);
                                        cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                        fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "ARCHIVEID ='" + personalid + "'");
                                    }
                            }
                        } else if (upType.equals(TYPE_DIABETES)) {
                            String happentime=obj.getString("happentime");
                            // 糖尿病
                            List<CD_DIABETESFOLLOWUP> findAllByWhere = fdbManage
                                    .findAllByWhere(CD_DIABETESFOLLOWUP.class, "IDCARD ='" + cardid + "' and FOLLOWUP_DATE='"+happentime+" 00:00:00'");
                            if (findAllByWhere.size() > 0) {
                                CD_DIABETESFOLLOWUP cd_DIABETESFOLLOWUP = findAllByWhere.get(0);
                                cd_DIABETESFOLLOWUP.setIS_UPDATE("N");
                                fdbManage.updata(cd_DIABETESFOLLOWUP, "IDCARD ='" + cardid + "' and FOLLOWUP_DATE='"+happentime+" 00:00:00'");
                            }else{
                                List<CD_DIABETESFOLLOWUP> findAllByWhere1 = fdbManage
                                        .findAllByWhere(CD_DIABETESFOLLOWUP.class, "IDCARD ='" + cardid.toLowerCase() + "'");
                                if(findAllByWhere1.size()>0){
                                    CD_DIABETESFOLLOWUP cd_DIABETESFOLLOWUP = findAllByWhere1.get(0);
                                    cd_DIABETESFOLLOWUP.setIS_UPDATE("N");
                                    fdbManage.updata(cd_DIABETESFOLLOWUP, "IDCARD ='" + cardid.toLowerCase() + "' and FOLLOWUP_DATE='"+happentime+" 00:00:00'");
                                }
                                    List<CD_DIABETESFOLLOWUP> findAllByWhere2 = fdbManage
                                            .findAllByWhere(CD_DIABETESFOLLOWUP.class, "ARCHIVEID ='" + personalid + "' and FOLLOWUP_DATE='"+happentime+" 00:00:00'");
                                    if(findAllByWhere2.size()>0){
                                        CD_DIABETESFOLLOWUP cd_HYPERTENSIONFOLLOWUP = findAllByWhere2.get(0);
                                        cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                        fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "ARCHIVEID ='" + personalid + "' and FOLLOWUP_DATE='"+happentime+" 00:00:00'");
                                    }
                            }
                        } else if (upType.equals(TYPE_TUBERCULOSIS_BASE_INFO)) {
                            /*肺结核第一次随访*/
                            List<CD_TUBERCULOSIS_BASEINFO> findAllByWhere = fdbManage
                                    .findAllByWhere(CD_TUBERCULOSIS_BASEINFO.class, "IDCARD ='" + cardid + "'");
                            if (findAllByWhere.size() > 0) {
                                CD_TUBERCULOSIS_BASEINFO cdTuberculosisBaseinfo = findAllByWhere.get(0);
                                cdTuberculosisBaseinfo.setIS_UPDATE("N");
                                fdbManage.updata(cdTuberculosisBaseinfo, "IDCARD ='" + cardid + "'");
                            }else{
                                List<CD_TUBERCULOSIS_BASEINFO> findAllByWhere1 = fdbManage
                                        .findAllByWhere(CD_TUBERCULOSIS_BASEINFO.class, "IDCARD ='" + cardid.toLowerCase() + "'");
                                if(findAllByWhere1.size()>0){
                                    CD_TUBERCULOSIS_BASEINFO cdTuberculosisBaseinfo = findAllByWhere1.get(0);
                                    cdTuberculosisBaseinfo.setIS_UPDATE("N");
                                    fdbManage.updata(cdTuberculosisBaseinfo, "IDCARD ='" + cardid.toLowerCase() + "'");
                                }
                                    List<CD_TUBERCULOSIS_BASEINFO> findAllByWhere2 = fdbManage
                                            .findAllByWhere(CD_TUBERCULOSIS_BASEINFO.class, "ARCHIVEID ='" + personalid + "'");
                                    if(findAllByWhere2.size()>0){
                                        CD_TUBERCULOSIS_BASEINFO cd_HYPERTENSIONFOLLOWUP = findAllByWhere2.get(0);
                                        cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                        fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "ARCHIVEID ='" + personalid + "'");
                                    }
                            }
                        } else if (upType.equals(TYPE_TUBERCULOSIS_FOLLOW_INFO)) {
                            /*肺结核随访信息*/
                            List<CD_TUBERCULOSIS_FOLLOWUP> findAllByWhere = fdbManage
                                    .findAllByWhere(CD_TUBERCULOSIS_FOLLOWUP.class, "IDCARD ='" + cardid + "'");
                            if (findAllByWhere.size() > 0) {
                                CD_TUBERCULOSIS_FOLLOWUP cdTuberculosisFollowup = findAllByWhere.get(0);
                                cdTuberculosisFollowup.setIS_UPDATE("N");
                                fdbManage.updata(cdTuberculosisFollowup, "IDCARD ='" + cardid + "'");
                            }else{
                                List<CD_TUBERCULOSIS_FOLLOWUP> findAllByWhere1 = fdbManage
                                        .findAllByWhere(CD_TUBERCULOSIS_FOLLOWUP.class, "IDCARD ='" + cardid.toLowerCase() + "'");
                                if(findAllByWhere1.size()>0){
                                    CD_TUBERCULOSIS_FOLLOWUP cdTuberculosisFollowup = findAllByWhere1.get(0);
                                    cdTuberculosisFollowup.setIS_UPDATE("N");
                                    fdbManage.updata(cdTuberculosisFollowup, "IDCARD ='" + cardid.toLowerCase() + "'");
                                }
                                    List<CD_TUBERCULOSIS_FOLLOWUP> findAllByWhere2 = fdbManage
                                            .findAllByWhere(CD_TUBERCULOSIS_FOLLOWUP.class, "ARCHIVEID ='" + personalid + "'");
                                    if(findAllByWhere2.size()>0){
                                        CD_TUBERCULOSIS_FOLLOWUP cd_HYPERTENSIONFOLLOWUP = findAllByWhere2.get(0);
                                        cd_HYPERTENSIONFOLLOWUP.setIS_UPDATE("N");
                                        fdbManage.updata(cd_HYPERTENSIONFOLLOWUP, "ARCHIVEID ='" + personalid + "'");
                                    }
                            }
                        } else if (upType.equals(TYPE_HEALTHCHECK)) {
                            // 健康体检_客户体检基本信息(症状)
                            List<ARCHIVE_CUSTOMERBASEINFO> customerbaseinfos = fdbManage
                                    .findAllByWhere(ARCHIVE_CUSTOMERBASEINFO.class, "IDCARD ='" + cardid + "'");
                            if (customerbaseinfos.size() > 0) {
                                ARCHIVE_CUSTOMERBASEINFO cd_CUSTOMERBASEINFO = customerbaseinfos.get(0);
                                cd_CUSTOMERBASEINFO.setIS_UPDATE("N");
                                fdbManage.updata(cd_CUSTOMERBASEINFO, "IDCARD ='" + cardid + "'");
                            }else{
                                List<ARCHIVE_CUSTOMERBASEINFO> customerbaseinfos1 = fdbManage
                                        .findAllByWhere(ARCHIVE_CUSTOMERBASEINFO.class, "IDCARD ='" + cardid.toLowerCase() + "'");
                                if(customerbaseinfos1.size()>0){
                                    ARCHIVE_CUSTOMERBASEINFO cd_CUSTOMERBASEINFO = customerbaseinfos1.get(0);
                                    cd_CUSTOMERBASEINFO.setIS_UPDATE("N");
                                    fdbManage.updata(cd_CUSTOMERBASEINFO, "IDCARD ='" + cardid.toLowerCase() + "'");
                                }
                            }

                        } else if (upType.equals(TYPE_QYYH)) {
                            //签约用户
                            List<JTYSCustomerDoctorCont> jtysCustomerDoctorConts = fdbManage
                                    .findAllByWhere(JTYSCustomerDoctorCont.class, "cardNum ='" + cardNum + "'");
                            if (jtysCustomerDoctorConts.size() > 0) {
                                JTYSCustomerDoctorCont jtysCustomerDoctorCont = jtysCustomerDoctorConts.get(0);
                                jtysCustomerDoctorCont.setSign("1");
                                fdbManage.updata(jtysCustomerDoctorCont, "cardNum ='" + cardNum + "'");
                            }else{
                                List<JTYSCustomerDoctorCont> jtysCustomerDoctorConts1 = fdbManage
                                        .findAllByWhere(JTYSCustomerDoctorCont.class, "cardNum ='" + cardNum.toLowerCase() + "'");
                                if(jtysCustomerDoctorConts1.size()>0){
                                    JTYSCustomerDoctorCont jtysCustomerDoctorCont = jtysCustomerDoctorConts1.get(0);
                                    jtysCustomerDoctorCont.setSign("1");
                                    fdbManage.updata(jtysCustomerDoctorCont, "cardNum ='" + cardNum.toLowerCase() + "'");
                                }
                            }

                        } else if (upType.equals(TYPE_FWMYD)) {
                            //服务满意度用户
                            List<JTYSDoctorEvaluateBean> jtysDoctorEvaluateBeen = fdbManage
                                    .findAllByWhere(JTYSDoctorEvaluateBean.class, "cardNum ='" + cardNum + "'");
                            if (jtysDoctorEvaluateBeen.size() > 0) {
                                JTYSDoctorEvaluateBean jtysDoctorEvaluateBean = jtysDoctorEvaluateBeen.get(0);
                                jtysDoctorEvaluateBean.setSign("1");
                                fdbManage.updata(jtysDoctorEvaluateBean, "cardNum ='" + cardNum + "'");
                            }else{
                                List<JTYSDoctorEvaluateBean> jtysDoctorEvaluateBeen1 = fdbManage
                                        .findAllByWhere(JTYSDoctorEvaluateBean.class, "cardNum ='" + cardNum.toLowerCase() + "'");
                                if(jtysDoctorEvaluateBeen1.size()>0){
                                    JTYSDoctorEvaluateBean jtysDoctorEvaluateBean = jtysDoctorEvaluateBeen1.get(0);
                                    jtysDoctorEvaluateBean.setSign("1");
                                    fdbManage.updata(jtysDoctorEvaluateBean, "cardNum ='" + cardNum.toLowerCase() + "'");
                                }
                            }

                        }else if(upType.equals(TYPE_LVYUEJL)){
                            List<LvYueFuWuBean> lvYueFuWuBeans = fdbManage
                                    .findAllByWhere(LvYueFuWuBean.class, "cardNum ='" + cardNum + "'");
                            if(lvYueFuWuBeans.size()>0){
                                for(LvYueFuWuBean lvYueFuWuBean:lvYueFuWuBeans){
                                    lvYueFuWuBean.setIs_Update("N");
                                    fdbManage.updata(lvYueFuWuBean,"id='"+lvYueFuWuBean.getId()+"'");
                                }
                            }else{
                                List<LvYueFuWuBean> lvYueFuWuBeans2 = fdbManage
                                        .findAllByWhere(LvYueFuWuBean.class, "cardNum ='" + cardNum.toLowerCase() + "'");
                                if(lvYueFuWuBeans2.size()>0){
                                    for(LvYueFuWuBean lvYueFuWuBean:lvYueFuWuBeans2){
                                        lvYueFuWuBean.setIs_Update("N");
                                        fdbManage.updata(lvYueFuWuBean,"id='"+lvYueFuWuBean.getId()+"'");
                                    }
                                }
                            }


                        } else if (upType.equals(TYPE_PICTURE)) {

                        } else if (upType.equals(TYPE_OLD_PHYSIQUE)) {
                            List<OLD_MEDICINE_CN> old_medicine_cns = fdbManage
                                    .findAllByWhere(OLD_MEDICINE_CN.class, "IDCARD ='" + cardid + "'");
                            if (old_medicine_cns.size() > 0) {
                                OLD_MEDICINE_CN old_medicine_cn = old_medicine_cns.get(0);
                                old_medicine_cn.setIS_UPDATE("N");
                                fdbManage.updata(old_medicine_cn, "IDCARD ='" + cardid + "'");
                            }else{
                                List<OLD_MEDICINE_CN> old_medicine_cns1 = fdbManage
                                        .findAllByWhere(OLD_MEDICINE_CN.class, "IDCARD ='" + cardid.toLowerCase() + "'");
                                if(old_medicine_cns1.size()>0){
                                    OLD_MEDICINE_CN old_medicine_cn = old_medicine_cns1.get(0);
                                    old_medicine_cn.setIS_UPDATE("N");
                                    fdbManage.updata(old_medicine_cn, "IDCARD ='" + cardid.toLowerCase() + "'");
                                }
                            }

                        } else if (upType.equals(TYPE_OLD_SELF_HELP)) {
                            List<OLDER_SELFCAREABILITY> older_selfcareabilities = fdbManage
                                    .findAllByWhere(OLDER_SELFCAREABILITY.class, "IDCARD ='" + cardid + "'");
                            if (older_selfcareabilities.size() > 0) {
                                OLDER_SELFCAREABILITY older_selfcareability = older_selfcareabilities.get(0);
                                older_selfcareability.setIS_UPDATE("N");
                                fdbManage.updata(older_selfcareability, "IDCARD ='" + cardid + "'");
                            }else{
                                List<OLDER_SELFCAREABILITY> older_selfcareabilities1 = fdbManage
                                        .findAllByWhere(OLDER_SELFCAREABILITY.class, "IDCARD ='" + cardid.toLowerCase() + "'");
                                if(older_selfcareabilities1.size()>0){
                                    OLDER_SELFCAREABILITY older_selfcareability = older_selfcareabilities1.get(0);
                                    older_selfcareability.setIS_UPDATE("N");
                                    fdbManage.updata(older_selfcareability, "IDCARD ='" + cardid.toLowerCase() + "'");
                                }
                            }
                        } else if (upType.equals(TYPE_XSRFS)) {
                            //新生儿访视
                            List<CHILD_NEWBORN_FOLLOWUP> child_newborn_followups = fdbManage
                                    .findAllByWhere(CHILD_NEWBORN_FOLLOWUP.class, "ARCHIVEID ='" + personalid + "'");
                            if (child_newborn_followups.size() > 0) {
                                CHILD_NEWBORN_FOLLOWUP child_newborn_followup = child_newborn_followups.get(0);
                                child_newborn_followup.setIS_UPDATE("N");
                                fdbManage.updata(child_newborn_followup, "ARCHIVEID ='" + personalid + "'");
                            }
                        } else if (upType.equals(TYPE_ONEMONTH)) {
                            //满月龄
                            List<CHILD_WITHIN_ONE_YEAR_OLD> childWithinOneYearOlds = fdbManage
                                    .findAllByWhere(CHILD_WITHIN_ONE_YEAR_OLD.class, "ARCHIVEID ='" + personalid + "' AND FLAG = '1'");
                            if (childWithinOneYearOlds.size() > 0) {
                                CHILD_WITHIN_ONE_YEAR_OLD childWithinOneYearOld = childWithinOneYearOlds.get(0);
                                childWithinOneYearOld.setIS_UPDATE("N");
                                fdbManage.updata(childWithinOneYearOld, "ARCHIVEID ='" + personalid + "'AND FLAG = '1'");
                            }
                        } else if (upType.equals(TYPE_THREEMONTH)) {
                            //三月龄
                            List<CHILD_WITHIN_ONE_YEAR_OLD> childWithinOneYearOlds = fdbManage
                                    .findAllByWhere(CHILD_WITHIN_ONE_YEAR_OLD.class, "ARCHIVEID ='" + personalid + "' AND FLAG = '2'");
                            if (childWithinOneYearOlds.size() > 0) {
                                CHILD_WITHIN_ONE_YEAR_OLD childWithinOneYearOld = childWithinOneYearOlds.get(0);
                                childWithinOneYearOld.setIS_UPDATE("N");
                                fdbManage.updata(childWithinOneYearOld, "ARCHIVEID ='" + personalid + "'AND FLAG = '2'");
                            }
                        } else if (upType.equals(TYPE_SIXMONTH)) {
                            //六月龄
                            List<CHILD_WITHIN_ONE_YEAR_OLD> childWithinOneYearOlds = fdbManage
                                    .findAllByWhere(CHILD_WITHIN_ONE_YEAR_OLD.class, "ARCHIVEID ='" + personalid + "' AND FLAG = '3'");
                            if (childWithinOneYearOlds.size() > 0) {
                                CHILD_WITHIN_ONE_YEAR_OLD childWithinOneYearOld = childWithinOneYearOlds.get(0);
                                childWithinOneYearOld.setIS_UPDATE("N");
                                fdbManage.updata(childWithinOneYearOld, "ARCHIVEID ='" + personalid + "'AND FLAG = '3'");
                            }
                        } else if (upType.equals(TYPE_EIGHTMONTH)) {
                            //八月龄
                            List<CHILD_WITHIN_ONE_YEAR_OLD> childWithinOneYearOlds = fdbManage
                                    .findAllByWhere(CHILD_WITHIN_ONE_YEAR_OLD.class, "ARCHIVEID ='" + personalid + "' AND FLAG = '4'");
                            if (childWithinOneYearOlds.size() > 0) {
                                CHILD_WITHIN_ONE_YEAR_OLD childWithinOneYearOld = childWithinOneYearOlds.get(0);
                                childWithinOneYearOld.setIS_UPDATE("N");
                                fdbManage.updata(childWithinOneYearOld, "ARCHIVEID ='" + personalid + "'AND FLAG = '4'");
                            }
                        } else if (upType.equals(TYPE_12MONTH)) {
                            //12月龄
                            List<CHILD_ONE2THREE_YEAR_OLD> childOne2THREEYearOlds = fdbManage
                                    .findAllByWhere(CHILD_ONE2THREE_YEAR_OLD.class, "ARCHIVEID ='" + personalid + "' AND FLAG = '1'");
                            if (childOne2THREEYearOlds.size() > 0) {
                                CHILD_ONE2THREE_YEAR_OLD childOne2THREEYearOld = childOne2THREEYearOlds.get(0);
                                childOne2THREEYearOld.setIS_UPDATE("N");
                                fdbManage.updata(childOne2THREEYearOld, "ARCHIVEID ='" + personalid + "'AND FLAG = '1'");
                            }
                        } else if (upType.equals(TYPE_18MONTH)) {
                            //18月龄
                            List<CHILD_ONE2THREE_YEAR_OLD> childOne2THREEYearOlds = fdbManage
                                    .findAllByWhere(CHILD_ONE2THREE_YEAR_OLD.class, "ARCHIVEID ='" + personalid + "' AND FLAG = '2'");
                            if (childOne2THREEYearOlds.size() > 0) {
                                CHILD_ONE2THREE_YEAR_OLD childOne2THREEYearOld = childOne2THREEYearOlds.get(0);
                                childOne2THREEYearOld.setIS_UPDATE("N");
                                fdbManage.updata(childOne2THREEYearOld, "ARCHIVEID ='" + personalid + "'AND FLAG = '2'");
                            }
                        } else if (upType.equals(TYPE_24MONTH)) {
                            //24月龄
                            List<CHILD_ONE2THREE_YEAR_OLD> childOne2THREEYearOlds = fdbManage
                                    .findAllByWhere(CHILD_ONE2THREE_YEAR_OLD.class, "ARCHIVEID ='" + personalid + "' AND FLAG = '3'");
                            if (childOne2THREEYearOlds.size() > 0) {
                                CHILD_ONE2THREE_YEAR_OLD childOne2THREEYearOld = childOne2THREEYearOlds.get(0);
                                childOne2THREEYearOld.setIS_UPDATE("N");
                                fdbManage.updata(childOne2THREEYearOld, "ARCHIVEID ='" + personalid + "'AND FLAG = '3'");
                            }
                        } else if (upType.equals(TYPE_30MONTH)) {
                            //30月龄
                            List<CHILD_ONE2THREE_YEAR_OLD> childOne2THREEYearOlds = fdbManage
                                    .findAllByWhere(CHILD_ONE2THREE_YEAR_OLD.class, "ARCHIVEID ='" + personalid + "' AND FLAG = '4'");
                            if (childOne2THREEYearOlds.size() > 0) {
                                CHILD_ONE2THREE_YEAR_OLD childOne2THREEYearOld = childOne2THREEYearOlds.get(0);
                                childOne2THREEYearOld.setIS_UPDATE("N");
                                fdbManage.updata(childOne2THREEYearOld, "ARCHIVEID ='" + personalid + "'AND FLAG = '4'");
                            }
                        } else if (upType.equals(TYPE_3YEAR)) {
                            //3岁龄
                            List<CHILD_THREE2SIX_YEAR_OLD> childThree2SixYearOlds = fdbManage
                                    .findAllByWhere(CHILD_THREE2SIX_YEAR_OLD.class, "ARCHIVEID ='" + personalid + "' AND FLAG = '3'");
                            if (childThree2SixYearOlds.size() > 0) {
                                CHILD_THREE2SIX_YEAR_OLD childThree2SixYearOld = childThree2SixYearOlds.get(0);
                                childThree2SixYearOld.setIS_UPDATE("N");
                                fdbManage.updata(childThree2SixYearOld, "ARCHIVEID ='" + personalid + "'AND FLAG = '3'");
                            }
                        } else if (upType.equals(TYPE_4YEAR)) {
                            //4岁龄
                            List<CHILD_THREE2SIX_YEAR_OLD> childThree2SixYearOlds = fdbManage
                                    .findAllByWhere(CHILD_THREE2SIX_YEAR_OLD.class, "ARCHIVEID ='" + personalid + "' AND FLAG = '4'");
                            if (childThree2SixYearOlds.size() > 0) {
                                CHILD_THREE2SIX_YEAR_OLD childThree2SixYearOld = childThree2SixYearOlds.get(0);
                                childThree2SixYearOld.setIS_UPDATE("N");
                                fdbManage.updata(childThree2SixYearOld, "ARCHIVEID ='" + personalid + "'AND FLAG = '4'");
                            }
                        } else if (upType.equals(TYPE_5YEAR)) {
                            //5岁龄
                            List<CHILD_THREE2SIX_YEAR_OLD> childThree2SixYearOlds = fdbManage
                                    .findAllByWhere(CHILD_THREE2SIX_YEAR_OLD.class, "ARCHIVEID ='" + personalid + "' AND FLAG = '5'");
                            if (childThree2SixYearOlds.size() > 0) {
                                CHILD_THREE2SIX_YEAR_OLD childThree2SixYearOld = childThree2SixYearOlds.get(0);
                                childThree2SixYearOld.setIS_UPDATE("N");
                                fdbManage.updata(childThree2SixYearOld, "ARCHIVEID ='" + personalid + "'AND FLAG = '5'");
                            }
                        } else if (upType.equals(TYPE_6YEAR)) {
                            //6岁龄
                            List<CHILD_THREE2SIX_YEAR_OLD> childThree2SixYearOlds = fdbManage
                                    .findAllByWhere(CHILD_THREE2SIX_YEAR_OLD.class, "ARCHIVEID ='" + personalid + "' AND FLAG = '6'");
                            if (childThree2SixYearOlds.size() > 0) {
                                CHILD_THREE2SIX_YEAR_OLD childThree2SixYearOld = childThree2SixYearOlds.get(0);
                                childThree2SixYearOld.setIS_UPDATE("N");
                                fdbManage.updata(childThree2SixYearOld, "ARCHIVEID ='" + personalid + "'AND FLAG = '6'");
                            }
                        }
                        /*****************************************添加孕妇下载请求************************************************/
                        else if (upType.equals(TYPE_1TIMES)) {
                            /*产前随访第一次*/
                            List<GRAVIDA_FIRSTFOLLOWUP> gravidaFirstfollowups = fdbManage
                                    .findAllByWhere(GRAVIDA_FIRSTFOLLOWUP.class, "ARCHIVEID ='" + personalid + "'");
                            if (gravidaFirstfollowups.size() > 0) {
                                GRAVIDA_FIRSTFOLLOWUP gravidaFirstfollowups1 = gravidaFirstfollowups.get(0);
                                gravidaFirstfollowups1.setIS_UPDATE("N");
                                fdbManage.updata(gravidaFirstfollowups, "ARCHIVEID ='" + personalid + "'");
                            }
                        } else if (upType.equals(TYPE_2TIMES)) {
                            /*产前随访第二次*/
                            List<GRAVIDA_TWO2FIVE_FOLLOWUP> gravidaTwo2fiveFollowups = fdbManage
                                    .findAllByWhere(GRAVIDA_TWO2FIVE_FOLLOWUP.class, "ARCHIVEID ='" + personalid + "'AND TIMES = '2'");
                            if (gravidaTwo2fiveFollowups.size() > 0) {
                                GRAVIDA_TWO2FIVE_FOLLOWUP gravidaTwo2fiveFollowup = gravidaTwo2fiveFollowups.get(0);
                                gravidaTwo2fiveFollowup.setIS_UPDATE("N");
                                fdbManage.updata(gravidaTwo2fiveFollowup, "ARCHIVEID ='" + personalid + "' AND TIMES = '2'");
                            }
                        } else if (upType.equals(TYPE_3TIMES)) {
                            /*产前随访第三次*/
                            List<GRAVIDA_TWO2FIVE_FOLLOWUP> gravidaTwo2fiveFollowups = fdbManage
                                    .findAllByWhere(GRAVIDA_TWO2FIVE_FOLLOWUP.class, "ARCHIVEID ='" + personalid + "' AND TIMES = '3'");
                            if (gravidaTwo2fiveFollowups.size() > 0) {
                                GRAVIDA_TWO2FIVE_FOLLOWUP gravidaTwo2fiveFollowup = gravidaTwo2fiveFollowups.get(0);
                                gravidaTwo2fiveFollowup.setIS_UPDATE("N");
                                fdbManage.updata(gravidaTwo2fiveFollowup, "ARCHIVEID ='" + personalid + "' AND TIMES = '3'");
                            }
                        } else if (upType.equals(TYPE_4TIMES)) {
                            /*产前随访第四次*/
                            List<GRAVIDA_TWO2FIVE_FOLLOWUP> gravidaTwo2fiveFollowups = fdbManage
                                    .findAllByWhere(GRAVIDA_TWO2FIVE_FOLLOWUP.class, "ARCHIVEID ='" + personalid + "' AND TIMES = '4'");
                            if (gravidaTwo2fiveFollowups.size() > 0) {
                                GRAVIDA_TWO2FIVE_FOLLOWUP gravidaTwo2fiveFollowup = gravidaTwo2fiveFollowups.get(0);
                                gravidaTwo2fiveFollowup.setIS_UPDATE("N");
                                fdbManage.updata(gravidaTwo2fiveFollowup, "ARCHIVEID ='" + personalid + "' AND TIMES = '4'");
                            }
                        } else if (upType.equals(TYPE_5TIMES)) {
                            /*产前随访第五次*/
                            List<GRAVIDA_TWO2FIVE_FOLLOWUP> gravidaTwo2fiveFollowups = fdbManage
                                    .findAllByWhere(GRAVIDA_TWO2FIVE_FOLLOWUP.class, "ARCHIVEID ='" + personalid + "' AND TIMES = '5'");
                            if (gravidaTwo2fiveFollowups.size() > 0) {
                                GRAVIDA_TWO2FIVE_FOLLOWUP gravidaTwo2fiveFollowup = gravidaTwo2fiveFollowups.get(0);
                                gravidaTwo2fiveFollowup.setIS_UPDATE("N");
                                fdbManage.updata(gravidaTwo2fiveFollowup, "ARCHIVEID ='" + personalid + "' AND TIMES = '5'");
                            }
                        } else if (upType.equals(TYPE_POSTNATAL_VISITS)) {
                            /*产后访视*/
                            List<GRAVIDA_POSTPARTUM> gravidaPostpartums = fdbManage
                                    .findAllByWhere(GRAVIDA_POSTPARTUM.class, "ARCHIVEID ='" + personalid + "'");
                            if (gravidaPostpartums.size() > 0) {
                                GRAVIDA_POSTPARTUM gravidaPostpartum = gravidaPostpartums.get(0);
                                gravidaPostpartum.setIS_UPDATE("N");
                                fdbManage.updata(gravidaPostpartum, "ARCHIVEID ='" + personalid + "'");
                            }
                        } else if (upType.equals(TYPE_42DAYS)) {
                            /* 产后四十二天访视*/
                            List<GRAVIDA_POSTPARTUM_42DAY> gravidaPostpartum42Days = fdbManage
                                    .findAllByWhere(GRAVIDA_POSTPARTUM_42DAY.class, "ARCHIVEID ='" + personalid + "'");
                            if (gravidaPostpartum42Days.size() > 0) {
                                GRAVIDA_POSTPARTUM_42DAY gravidaPostpartum42Day = gravidaPostpartum42Days.get(0);
                                gravidaPostpartum42Day.setIS_UPDATE("N");
                                fdbManage.updata(gravidaPostpartum42Day, "ARCHIVEID ='" + personalid + "'");
                            }
                        }else if(upType.equals(TYPE_FEIXINBING)){
                            List<FeiXinBingFollowupNew> feiXinBingFollowups=fdbManage.findAllByWhere(FeiXinBingFollowupNew.class,"idcard ='" + cardid + "'");
                            if(feiXinBingFollowups.size()>0){
                                FeiXinBingFollowupNew feiXinBingFollowup=feiXinBingFollowups.get(0);
                                feiXinBingFollowup.setIsUpdate("N");
                                fdbManage.updata(feiXinBingFollowup,"idcard ='" + cardid + "'");
                            }
                        }else if(upType.equals(TYPE_LEIFENGSHI)){
                            List<LeiFengShiFollowupNew> feiXinBingFollowups=fdbManage.findAllByWhere(LeiFengShiFollowupNew.class,"idcard ='" + cardid + "'");
                            if(feiXinBingFollowups.size()>0){
                                LeiFengShiFollowupNew feiXinBingFollowup=feiXinBingFollowups.get(0);
                                feiXinBingFollowup.setIsUpdate("N");
                                fdbManage.updata(feiXinBingFollowup,"idcard ='" + cardid + "'");
                            }
                        }else if(upType.equals(TYPE_FENGSHIBING)){
                            List<FengShiBingFollowupNew> feiXinBingFollowups=fdbManage.findAllByWhere(FengShiBingFollowupNew.class,"idcard ='" + cardid + "'");
                            if(feiXinBingFollowups.size()>0){
                                FengShiBingFollowupNew feiXinBingFollowup=feiXinBingFollowups.get(0);
                                feiXinBingFollowup.setIsUpdate("N");
                                fdbManage.updata(feiXinBingFollowup,"idcard ='" + cardid + "'");
                            }
                        }else if(upType.equals(TYPE_MANZUFEI)){
                            List<ManZuFeiFollowupNew> feiXinBingFollowups=fdbManage.findAllByWhere(ManZuFeiFollowupNew.class,"idcard ='" + cardid + "'");
                            if(feiXinBingFollowups.size()>0){
                                ManZuFeiFollowupNew feiXinBingFollowup=feiXinBingFollowups.get(0);
                                feiXinBingFollowup.setIsUpdate("N");
                                fdbManage.updata(feiXinBingFollowup,"idcard ='" + cardid + "'");
                            }
                        }
                    }else if(state.equals("008")){
                        if(upType.equals(TYPE_QYYH)){
                            i1++;
                            //签约用户
                            List<JTYSCustomerDoctorCont> jtysCustomerDoctorConts = fdbManage
                                    .findAllByWhere(JTYSCustomerDoctorCont.class, "cardNum ='" + cardNum + "'");
                            if (jtysCustomerDoctorConts.size() > 0) {
                                JTYSCustomerDoctorCont jtysCustomerDoctorCont = jtysCustomerDoctorConts.get(0);
                                jtysCustomerDoctorCont.setSign("1");
                                fdbManage.updata(jtysCustomerDoctorCont, "cardNum ='" + cardNum + "'");
                                List<JTYS_SignPictureData> jtys_signPictureDatas=fdbManage.findAllByWhere(JTYS_SignPictureData.class,"cardNum ='" + cardNum + "'");
                                if(jtys_signPictureDatas.size()>0){
                                    for(JTYS_SignPictureData ss:jtys_signPictureDatas){
                                        ss.setIsUpdate("N");
                                        fdbManage.updata(ss, "ID ='" + ss.getID() + "'");
                                    }
                                }
                            }else{
                                List<JTYSCustomerDoctorCont> jtysCustomerDoctorConts1 = fdbManage
                                        .findAllByWhere(JTYSCustomerDoctorCont.class, "cardNum ='" + cardNum.toLowerCase() + "'");
                                if(jtysCustomerDoctorConts1.size()>0){
                                    JTYSCustomerDoctorCont jtysCustomerDoctorCont = jtysCustomerDoctorConts1.get(0);
                                    jtysCustomerDoctorCont.setSign("1");
                                    fdbManage.updata(jtysCustomerDoctorCont, "cardNum ='" + cardNum.toLowerCase() + "'");
                                    List<JTYS_SignPictureData> jtys_signPictureDatas=fdbManage.findAllByWhere(JTYS_SignPictureData.class,"cardNum ='" + cardNum.toLowerCase() + "'");
                                    if(jtys_signPictureDatas.size()>0){
                                        for(JTYS_SignPictureData ss:jtys_signPictureDatas){
                                            ss.setIsUpdate("N");
                                            fdbManage.updata(ss, "ID ='" + ss.getID() + "'");
                                        }
                                    }
                                }
                            }
                        }

                    } else {
                        i2++;

                        if(state.equals("001")){
                           if(upType.equals(TYPE_PERSONALINFO)) {
                               FileHelper.addTxtToFileWrite("表名：ARCHIVE_BASEINFO(个人基本信息);"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:无此人档案信息");
                           }else if(upType.equals(TYPE_HYPERTENSION)){
                               FileHelper.addTxtToFileWrite("表名：CD_HYPERTENSIONFOLLOWUP（高血压随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:无此人档案信息");
                           }else if(upType.equals(TYPE_DIABETES)){
                               FileHelper.addTxtToFileWrite("表名：CD_DIABETESFOLLOWUP（糖尿病随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:无此人档案信息");
                           }else if(upType.equals(TYPE_QYYH)){
                               FileHelper.addTxtToFileWrite("表名：JTYSCustomerDoctorCont（随访用户）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:无此人档案信息");
                           }
                        }else if(state.equals("002")){
                            if(upType.equals(TYPE_PERSONALINFO)) {
                                FileHelper.addTxtToFileWrite("表名：ARCHIVE_BASEINFO(个人基本信息);"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:疾病类型不匹配");
                            }else if(upType.equals(TYPE_HYPERTENSION)){
                                FileHelper.addTxtToFileWrite("表名：CD_HYPERTENSIONFOLLOWUP（高血压随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+";疾病类型不匹配");
                            }else if(upType.equals(TYPE_DIABETES)){
                                FileHelper.addTxtToFileWrite("表名：CD_DIABETESFOLLOWUP（糖尿病随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:疾病类型不匹配");
                            }else if(upType.equals(TYPE_QYYH)){
                                FileHelper.addTxtToFileWrite("表名：JTYSCustomerDoctorCont（随访用户）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:疾病类型不匹配");
                            }
                        }else if(state.equals("003")){
                            if(upType.equals(TYPE_PERSONALINFO)) {
                                FileHelper.addTxtToFileWrite("表名：ARCHIVE_BASEINFO(个人基本信息);"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:人群类型不匹配");
                            }else if(upType.equals(TYPE_HYPERTENSION)){
                                FileHelper.addTxtToFileWrite("表名：CD_HYPERTENSIONFOLLOWUP（高血压随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+";人群类型不匹配");
                            }else if(upType.equals(TYPE_DIABETES)){
                                FileHelper.addTxtToFileWrite("表名：CD_DIABETESFOLLOWUP（糖尿病随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:人群类型不匹配");
                            }else if(upType.equals(TYPE_QYYH)){
                                FileHelper.addTxtToFileWrite("表名：JTYSCustomerDoctorCont（随访用户）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:人群类型不匹配");
                            }
                        }else if(state.equals("004")){
                            if(upType.equals(TYPE_PERSONALINFO)) {
                                FileHelper.addTxtToFileWrite("表名：ARCHIVE_BASEINFO(个人基本信息);"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因: json数据异常");
                            }else if(upType.equals(TYPE_HYPERTENSION)){
                                FileHelper.addTxtToFileWrite("表名：CD_HYPERTENSIONFOLLOWUP（高血压随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+"; json数据异常");
                            }else if(upType.equals(TYPE_DIABETES)){
                                FileHelper.addTxtToFileWrite("表名：CD_DIABETESFOLLOWUP（糖尿病随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因: json数据异常");
                            }else if(upType.equals(TYPE_QYYH)){
                                FileHelper.addTxtToFileWrite("表名：JTYSCustomerDoctorCont（随访用户）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因: json数据异常");
                            }
                        }else if(state.equals("005")){
                            if(upType.equals(TYPE_PERSONALINFO)) {
                                FileHelper.addTxtToFileWrite("表名：ARCHIVE_BASEINFO(个人基本信息);"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因: 未知异常插入失败");
                            }else if(upType.equals(TYPE_HYPERTENSION)){
                                FileHelper.addTxtToFileWrite("表名：CD_HYPERTENSIONFOLLOWUP（高血压随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+"; 未知异常插入失败");
                            }else if(upType.equals(TYPE_DIABETES)){
                                FileHelper.addTxtToFileWrite("表名：CD_DIABETESFOLLOWUP（糖尿病随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因: 未知异常插入失败");
                            }else if(upType.equals(TYPE_QYYH)){
                                FileHelper.addTxtToFileWrite("表名：JTYSCustomerDoctorCont（随访用户）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因: 未知异常插入失败");
                            }
                        }else if(state.equals("006")){
                            if(upType.equals(TYPE_PERSONALINFO)) {
                                FileHelper.addTxtToFileWrite("表名：ARCHIVE_BASEINFO(个人基本信息);"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:  json转换失败");
                            }else if(upType.equals(TYPE_HYPERTENSION)){
                                FileHelper.addTxtToFileWrite("表名：CD_HYPERTENSIONFOLLOWUP（高血压随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+";  json转换失败");
                            }else if(upType.equals(TYPE_DIABETES)){
                                FileHelper.addTxtToFileWrite("表名：CD_DIABETESFOLLOWUP（糖尿病随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:  json转换失败");
                            }else if(upType.equals(TYPE_QYYH)){
                                FileHelper.addTxtToFileWrite("表名：JTYSCustomerDoctorCont（随访用户）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:  json转换失败");
                            }
                        }else if(state.equals("007")){
                            if(upType.equals(TYPE_PERSONALINFO)) {
                                FileHelper.addTxtToFileWrite("表名：ARCHIVE_BASEINFO(个人基本信息);"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:  必填验证未通过"+"；未填字段："+fieldname);
                            }else if(upType.equals(TYPE_HYPERTENSION)){
                                FileHelper.addTxtToFileWrite("表名：CD_HYPERTENSIONFOLLOWUP（高血压随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+";  必填验证未通过"+"；未填字段："+fieldname);
                            }else if(upType.equals(TYPE_DIABETES)){
                                FileHelper.addTxtToFileWrite("表名：CD_DIABETESFOLLOWUP（糖尿病随访）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:  必填验证未通过"+"；未填字段："+fieldname);
                            }else if(upType.equals(TYPE_QYYH)){
                                FileHelper.addTxtToFileWrite("表名：JTYSCustomerDoctorCont（随访用户）;"+"CardNum:"+cardNum+",personalid:"+personalid+";错误原因:  必填验证未通过"+"；未填字段："+fieldname);
                            }
                        }
                    }
                }
            }
        } catch (JSONException e) {
            Log.e("JSONException", e.getMessage() + "---" + e.getCause());
        } finally {
            return new int[]{i1, i2};
        }



    }
}
